package com.css.dzj.zfjg.modules.statisticsa.controller;

import com.css.aq.server.service.BaseService;
import com.css.dzj.zfjg.common.util.R;
import com.css.dzj.zfjg.modules.statisticsa.service.StatisticsaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/statisticsa")
public class StatisticsaController {
    @Autowired
    private StatisticsaService statisticsaService;

    @Autowired
    private BaseService baseService;

    /**
     * 从Excel表格中批量导入数据到数据库
     *
     * @param file
     * @return
     */
    @PostMapping("/import")
    public R addFormExcel(@RequestParam("file") MultipartFile file) {
        try {
            statisticsaService.addFromExcel(file);
            baseService.logSuccess(3, "信用评估结果统计-A导入成功", "2");
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "信用评估结果统计-A导入失败", "2");
            return R.error(e.getMessage());
        }
    }
}
